﻿uap({
    mobile: {
        PopupAutoClose: function () {
            if (!uap.mobile._PopupAutoClose) {
                $(document).on('popupafterclose', '.ui-popup', function () {
                    $(this).remove();
                });
                uap.mobile._PopupAutoClose = true;
            }
        }
        , popupHTML: function (id, html) {
            uap.mobile.PopupAutoClose();
            $.mobile.activePage.append(html).trigger('pagecreate');
            document.body.appendChild(document.getElementById(id + '-screen'));
            document.body.appendChild(document.getElementById(id + '-popup'));
            $('#' + id).popup('open', { transition: $.mobile.defaultPageTransition });
        }
    }
    , loading: function (v) {
        if (v) {
            $.mobile.loading('show', {
                text: v,
                textVisible: true
            });
        } else {
            $.mobile.loading('hide');
        }
    }
    , alert: function (s, f, ss) {
        var ui = '<div id="jq-mob-alert" data-role="popup" data-close-btn="none" data-overlay-theme="a">';
        ui += '<div data-role="header"><h1>提示</h1></div>';
        ui += '<div data-role="content">';
        ui += '<h1>' + s + '</h1>';
        if (ss) ui += '<p>' + ss + '</p>';
        ui += '<a data-role="button" data-rel="back">确认</a>';
        ui += '</div>';
        ui += '</div>';
        uap.mobile.popupHTML('jq-mob-alert', ui);
    }
    , confirm: function (s, yes, no, ss) {
        var ui = '<div id="jq-mob-confirm" data-role="popup" data-close-btn="none" data-overlay-theme="a">';
        ui += '<div data-role="header"><h1>确认</h1></div>';
        ui += '<div data-role="content">';
        ui += '<h1>' + s + '</h1>';
        ui += '<p>' + ss + '</p>';
        ui += '<a data-role="button" data-inline="true" data-rel="back">取消</a>';
        ui += '<a data-role="button" data-inline="true" data-rel="back" data-theme="b">确认</a>';
        ui += '</div>';
        ui += '</div>';
        uap.mobile.popupHTML('jq-mob-confirm', ui);
    }
});
uap.init.push(function () {
    $.mobile.loadingMessageTextVisible = true;
    $.mobile.loadingMessageTheme = 'a';
    $.mobile.loadingMessage = '正在加载中...';
    $.mobile.pageLoadErrorMessage = '读取数据失败';
    $.mobile.pageLoadErrorMessageTheme = 'a';
    $.mobile.defaultPageTransition = 'slide';
});